package com.lanou.service.impl;

import com.lanou.entity.Page;
import com.lanou.entity.Person;
import com.lanou.mapper.PersonMapper;
import com.lanou.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//实现类
@Service
@Transactional //全类开启事务
public class PersonServiceImpl implements PersonService {

    @Autowired //注入实现类
    private PersonMapper personMapper;

    @Override
    @Transactional(readOnly = true) //是否开启事务
    public List<Person> findAll() {
        return personMapper.findAll();
    }

    @Override
    // @Transactional
    public Person add(Person person) {
        personMapper.insert(person);
        // int a = 1 / 0;
        return personMapper.findById(person.getPid());
    }

    @Override
    public List<Person> findByPage(Page page) {
        return personMapper.findByPage(page);
    }

    @Override
    public long countAll() {
        return personMapper.countAll();
    }
}